#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int n , tag;
int f[maxn];
int main()
{
    freopen("arena.in" , "r" , stdin);
    freopen("arena.out" , "w" , stdout);
    ios::sync_with_stdio(false);
    cin >> n;
    for (int i = 1 ; i <= n ; i++)
    {
         f[i] = i == 1 ? 0 : n + 1;
    }
    for (int i = 1 , x , y , t ; i <= n ; i++)
    {
        cin >> x >> t;
        if(t == 1)
        {
            tag++ , f[x] = -tag;
        }
        if(t == 2)
        {
            cin >> y , f[x] = min(f[x] , f[y]);
            if(x != y)
            {
                f[x]++;
            }
        }
    }
    for (int i = 1 ; i <= n ; i++)
    {
        cout << ((f[i] + tag) > n ? -1 : (f[i] + tag));
    }
    return 0;
}
